package com.ssm.serviceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.JobEntityMapper;
import com.ssm.entity.EnterpriseEntity;
import com.ssm.entity.JobEntity;
import com.ssm.service.JobService;
@Service("JobServiceImpl")
@Transactional
public class JobServiceImpl implements JobService {
   
    @Autowired
    private JobEntityMapper mapper;
	@Override
	public void save(JobEntity job) {
		mapper.insert(job);
		return;
	}

	@Override
	public boolean update(JobEntity job) {
		try {
			int result = mapper.updateByPrimaryKeySelective(job);
			System.out.print(result);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public JobEntity findById(String id) {
		JobEntity job = mapper.selectByPrimaryKey(id);		
		return job;
	}

	@Override
	public Map<String, Object> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<JobEntity> findWithPage(Integer page, Integer pageNum, String coId) {
		if (page == null || pageNum == null) {
			return new ArrayList<JobEntity>();
		} else {
			PageHelper.startPage(page, pageNum);
			try {
				List<JobEntity> jobs= mapper.findAll(coId);
				return jobs;
			}finally {
				// 保证线程安全
				PageHelper.clearPage();
			}
		}
	}

}
